package com.ww.wwojbackendmodel.entity;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ww.wwojbackendmodel.dto.question.JudgeCase;
import com.ww.wwojbackendmodel.dto.question.JudgeConfig;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * 题目
 * @TableName question
 */
@TableName(value ="question")
@Data
public class Question implements Serializable {
    /**
     * id
     */
    @TableId(type = IdType.ASSIGN_ID)
    private Long id;

    /**
     * 标题
     */
    private String title;

    /**
     * 内容
     */
    private String content;

    /**
     * 标签列表（json 数组）
     */
    private String tags;

    /**
     * 题目答案
     */
    private String answer;

    /**
     * 题目提交数
     */
    private Integer submitNum;

    /**
     * 题目通过数
     */
    private Integer acceptedNum;

    /**
     * 判题用例（json 数组）
     */
    private String judgeCase;

    /**
     * 判题配置（json 对象）
     */
    private String judgeConfig;

    /**
     * 点赞数
     */
    private Integer thumbNum;

    /**
     * 收藏数
     */
    private Integer favourNum;

    /**
     * 创建用户 id
     */
    private Long userId;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 是否删除
     */
    private Integer isDelete;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @TableField(exist = false)
    private List<String> tagsText;

    @TableField(exist = false)
    private List<JudgeCase> judgeCaseList;

    @TableField(exist = false)
    private JudgeConfig judgeConfigList;

    public void setTags(String tags) {
        this.tags = tags;
        this.tagsText = JSONUtil.toList(tags, String.class);
    }

    public void setJudgeCase(String judgeCase) {
        this.judgeCase = judgeCase;
        this.judgeCaseList = JSONUtil.toList(judgeCase, JudgeCase.class);
    }

    public void setJudgeConfig(String judgeConfig) {
        this.judgeConfig = judgeConfig;
        this.judgeConfigList = JSONUtil.toBean(judgeConfig, JudgeConfig.class);
    }
}